import { objDeepCopy,getCascaderObj ,getDateString} from "@/assets/js/common.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			
		},
		//返回上一页
		back(){
			this.$router.push({
				path:'listAllocation',
				query:{
					
				}
			});
		},
		//提交订单
		onConfirmNew(){
			
		},
		//取消订单
		cancelOrder() {
			
		},
		showNotSureBarCodeP1() {
			
		},
		showNotSureBarCodeP2(){
			
		},
		toSearchNotSureBarCode() {
			
		},
		//
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		tips(that, type, message) {
			let duration;
			type == 'success' ? duration = 3000 : duration = 10000;
			that.$message({
				message: message,
				type: type,
				duration: duration
			});
		},
		toggleTableDetail(val) {
			const obj = this.Model[val];
			if (obj.flag === true) {
				this.Model[val].src = require('@/assets/img/icon_collapse.png');
				this.Model[val].flag = false;
			} else {
				this.Model[val].src = require('@/assets/img/icon_unfold.png');
				this.Model[val].flag = true;
			}
		},
		handleSelectionChange(val) {
		  this.Model.TableSelectData = val;
		},
		handleCurrentChange(val) {
		  this.Model.pager.params.pageIndex = val;
		},
		handleSizeChange(val) {
		  this.Model.pager.params.pageSize = val;
		},
		cardClick(color) {
		  this.Model.cardSelected = color;
		},
		showChild(val) {
		  this.Model.searchFromData = val;
		},
		toSearch(val) {
			var params = {
					conditcion:this.Model.searchFromData
				}
			this.getCommodity(this,params)
		},
		toClear(val) {
		  this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
		  console.log(val);
		},
		//切换省市区
		handleItemChange(val) {
			console.log(val)
			if(val.length == 1){
				var provinceCode = val[0];
				this.getAllCity(this,provinceCode);
			}else if(val.length == 2){
				var provinceCode = val[0];
				var cityCode = val[1];
				this.getAllCounty(this,provinceCode,cityCode)
			}else{
				
			}
		},
		//联机选择器 选择结束触发
		changecascards(val) {
			
			var labelStr = '';
			var cascaderArr = this.getCascaderObj(val, this.Model.options);
			for (let i = 0; i < cascaderArr.length; i++) {
				labelStr += cascaderArr[i].label;
			}

			// this.Model.checkedAddress.location = labelStr;

			this.Model.checkedAddress.countryCode = 'CN';
			this.Model.checkedAddress.countryName = '中国';
			this.Model.checkedAddress.provinceCode = cascaderArr[0].code;
			this.Model.checkedAddress.provinceName = cascaderArr[0].label;
			this.Model.checkedAddress.cityCode = cascaderArr[1].code;
			this.Model.checkedAddress.cityName = cascaderArr[1].label;
			this.Model.checkedAddress.areaCode = cascaderArr[2].code;
			this.Model.checkedAddress.areaName = cascaderArr[2].label;
			console.log(this.Model.checkedAddress)
		},
		//遍历 得到label及value
		getCascaderObj(val,opt){
			return val.map(function (value, index, array) {
                for (var item of opt) {
                    if (item.code == value) {
						opt = item.children;
						return item;
					}
                }
                return null;
            });
		},
		//合计
		getSummaries(param) {
		var that = this;
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }else if(index === 5 || index === 6) {
			  const values = data.map(item => Number(item[column.property]));
			  sums[index] = values.reduce((prev, curr) => {
			    const value = Number(curr);
			    if (!isNaN(value)) {
			      return prev + curr;
			    } else {
			      return prev;
			    }
			  }, 0);
			  if(index === 6){
				that.Model.totlePrice = sums[index];
			  }else{
				
			  }
			  
		  }else{
			sums[index] = '/';
		  }
        });

        return sums;
      }
  }
}
export default Controller;
